package com.bupt.liutong.admin.bbs.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.bupt.liutong.admin.core.base.BaseAction;
import com.bupt.liutong.admin.bbs.bo.PostBo;
import com.bupt.liutong.admin.bbs.form.PostForm;
import com.bupt.liutong.util.BeanUtils;

public class PostAction extends BaseAction {

	private PostBo postBo;

	public ActionForward getPostsByPage(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		PostForm postForm = (PostForm) form;
		postForm.setParentId(new Long(-1));
		request.setAttribute("postFormList", postBo.getPostsByPage(
				postForm, request));
		putPageInfo(request, postForm);
		return mapping.findForward("getPostsByPageSuccess");
	}

	public ActionForward getRepliesByPage(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		PostForm postForm = (PostForm) form;
		request.setAttribute("postFormList", postBo.getPostsByPage(
				postForm, request));
		putPageInfo(request, postForm);
		return mapping.findForward("getRepliesByPageSuccess");
	}

	/*
	public ActionForward insertPost(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		request.setAttribute("eliteList", getOptionList(ctm.get("yesOrNo"), false));
		request.setAttribute("topList", getOptionList(ctm.get("yesOrNo"), false));
		request.setAttribute("lockList", getOptionList(ctm.get("yesOrNo"), false));
		request.setAttribute("hiddenList", getOptionList(ctm.get("yesOrNo"), false));
		
		return mapping.findForward("insertPostSuccess");
	}

	public ActionForward insertPostDo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		PostForm postForm = (PostForm) form;
		postBo.insertPost(postForm);
		return mapping.findForward("insertPostDoSuccess");
	}

	public ActionForward updatePost(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		request.setAttribute("eliteList", getOptionList(ctm.get("yesOrNo"), false));
		request.setAttribute("topList", getOptionList(ctm.get("yesOrNo"), false));
		request.setAttribute("lockList", getOptionList(ctm.get("yesOrNo"), false));
		request.setAttribute("hiddenList", getOptionList(ctm.get("yesOrNo"), false));
		
		PostForm postForm = (PostForm) form;
		BeanUtils.copyProperties(postForm, postBo.getPostById(postForm));
		return mapping.findForward("updatePostSuccess");
	}

	public ActionForward updatePostDo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		PostForm postForm = (PostForm) form;
		postBo.updatePost(postForm);
		return mapping.findForward("updatePostDoSuccess");
	}
	*/

	public ActionForward deletePosts(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String[] ids = request.getParameterValues("id");
		postBo.deletePosts(ids);
		return mapping.findForward("deletePostsSuccess");
	}

	public void setPostBo(PostBo postBo) {
		this.postBo = postBo;
	}
}

